package Enum2;

/**
 * 枚举类也会单独生成一个字节码文件
 * RED BLACK GREEN 都是枚举对象
 */
public enum TestEnum {
    RED(0.1,"红色"),BLACK(1.1,"黑色"),GREEN(2.1,"绿色");

    public String color;
    public double ordinal;
    TestEnum(double ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }


    @Override
    public String toString() {
        return "TestEnum{" +
                "color='" + color + '\'' +
                ", ordinal=" + ordinal +
                '}';
    }

    public static void main(String[] args) {
        TestEnum[] testEnum = TestEnum.values();

        for(int i = 0; i < testEnum.length; i++) {
            //ordinal会把每个对象的索引号也打印出来
            System.out.print(testEnum[i]+ " "+ testEnum[i].ordinal()+ " ");
        }
        System.out.println();

        TestEnum testEnum1 = TestEnum.valueOf("RED");
        System.out.println(testEnum1);
        System.out.println(BLACK.compareTo(GREEN));
    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum) {
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("颜色错误");
                break;
        }
    }
}
